# -*- coding: utf-8 -*-
 ##############################################
 ##                                            ##
 ##            Administración module            ##
 ##                                             ##
 ##                                             ##
 ##              from Basiq Series              ##
 ##           by Críptidos Digitales            ##
 ##                 GPL (c)2008                 ##
  ##                                            ##
    ##############################################

"""
"""

from PyQt4 import QtCore, QtGui

import administracion_ui

from cdWidgets import cdSlideFrame

import compras
import pedidos
import reportes
import ventas


class Controller():

    def __init__(self):
        # print 'administracion.Controller.__init__()'
        compras.session = session
        compras.app = app

        pedidos.session = session
        pedidos.app = app

        reportes.session = session

        ventas.session = session
        ventas.app = app

        self.controllers = []
        self.controllers.append(compras.Controller())
        self.controllers.append(ventas.Controller())
        self.controllers.append(pedidos.Controller())
        self.controllers.append(reportes.Controller())


    def initDb(self):
        compras.model.initDb()
        pedidos.model.initDb()
        reportes.model.initDb()
        ventas.model.initDb()


    def initForm(self):
        # print 'administracion.Controller.initForm()'
        session.mainForm.ui.administracion = Forma(session.mainForm.ui.baseFrame, owner=session.mainForm)
        session.mainForm.slide.addWidget(session.mainForm.ui.administracion)
        session.mainForm.ui.administracion.ui.title.hide()

        ## Tool Menu
        session.mainForm.ui.administracionTO = QtGui.QToolButton(session.mainForm.ui.sectionsFR)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(session.mainForm.ui.administracionTO.sizePolicy().hasHeightForWidth())
        session.mainForm.ui.administracionTO.setSizePolicy(sizePolicy)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("imagenes/Folder.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        session.mainForm.ui.administracionTO.setIcon(icon)
        session.mainForm.ui.administracionTO.setIconSize(QtCore.QSize(32, 32))
        session.mainForm.ui.administracionTO.setToolTip(u'Administración\nF8')
        session.mainForm.ui.administracionTO.setShortcut("F8")
        session.mainForm.ui.administracionTO.setAutoRaise(True)

        session.mainForm.ui.sectionsLY.insertWidget(0, session.mainForm.ui.administracionTO)
        session.mainForm.ui.administracionAC = QtGui.QAction(icon, u"", session.mainForm)
        session.mainForm.ui.administracionAC.setCheckable(False)
        session.mainForm.ui.administracionAC.setIconText(u"")
        session.mainForm.connect(session.mainForm.ui.administracionAC, QtCore.SIGNAL("triggered()"), session.mainForm.showAdministracion)

        session.mainForm.ui.administracionTO.setDefaultAction(session.mainForm.ui.administracionAC)

        ## Ventas
        session.mainForm.ui.administracion.ui.ventas = ventas.getForm(owner=session.mainForm, mode='consulta')
        session.mainForm.ui.administracion.ui.tabWidget.addTab(session.mainForm.ui.administracion.ui.ventas, u"&VENTAS")

        ## Compras
        session.mainForm.ui.administracion.ui.compras = compras.getForm(owner=session.mainForm)
        session.mainForm.ui.administracion.ui.tabWidget.addTab(session.mainForm.ui.administracion.ui.compras, u"&COMPRAS")

        ## Pedidos
        session.mainForm.ui.administracion.ui.pedidos = pedidos.getForm(owner=session.mainForm)
        session.mainForm.ui.administracion.ui.tabWidget.addTab(session.mainForm.ui.administracion.ui.pedidos, u"&PEDIDOS")

        ## Reportes
        session.mainForm.ui.administracion.ui.reportes = reportes.getForm(owner=session.mainForm)
        session.mainForm.ui.administracion.ui.tabWidget.addTab(session.mainForm.ui.administracion.ui.reportes, u'REPORTES')

        if session.mainForm.ui.administracion.ui.tabWidget.count() == 1:
            session.mainForm.ui.administracion.ui.tabWidget.tabBar().hide()

        session.mainForm.ui.administracion.ui.tabWidget.setCurrentIndex(0)



class Forma(QtGui.QFrame):

    def __init__(self, *args, **kwds):

        QtGui.QFrame.__init__(self, *args)

        self.ui = administracion_ui.Ui_Form()
        self.ui.setupUi(self)

        self.ui.title.setText(u"CONTROL DE PROCESOS")
        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(9*app.fontZoom)

        self.ui.tabWidget.setFont(font)
        self.ui.tabWidget.clear()


